package com.yidu.StockControl.controller;

import com.yidu.StockControl.entity.CashInventorys;
import com.yidu.StockControl.service.CashInventorysService;
import com.yidu.Util.util.Dbutil;
import com.yidu.Util.util.TableIdUtil;
import com.yidu.Util.util.TableNameUtil;
import com.yidu.Util.util.TableTimeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *  现金库存    现金库存    现金库存
 */
@RestController
public class CashInventorysController {
    @Resource
    CashInventorysService cashInventorysService;
    @Autowired
    Dbutil dbutil;

    @RequestMapping("/selectCashInventorys")
    public Map selectCashInventorys(String cashInventorysTime, String accounName, int page, int limit){
        System.out.println("查询  查询  查询");
        List<CashInventorys> list =cashInventorysService.selectCashInventorys(cashInventorysTime,accounName,page,limit);
        System.out.println(list+"===========================================================");
        int count = cashInventorysService.selectCashInventorysCount();
        Map map = new HashMap();
        map.put("code","0");
        map.put("msg",":");
        map.put("count",count);
        map.put("data",list);
        return map;
    }

    @RequestMapping("/insertCashInventorys")
    public int insertCashInventorys(CashInventorys cashInventorys, HttpServletRequest request){
        System.out.println("插入 插入");
        HttpSession session = request.getSession();
        String fundId = (String) session.getAttribute("fundId");
        String maxId3 = dbutil.getMaxId3(TableIdUtil.CSID, TableNameUtil.CIS, TableTimeUtil.CSTime, cashInventorys.getCashInventorysTime());
        cashInventorys.setCashInventorysId(maxId3);
        cashInventorys.setFundId(fundId);
        int i = cashInventorysService.insertCashInventorysId(cashInventorys);
        return i;
    }

    @RequestMapping("/updateCashInventorys")
    public void  updateCashInventorys(CashInventorys cashInventorys){
        System.out.println("修改 修改");
        cashInventorysService.updateCashInventorys(cashInventorys);
    }

    @RequestMapping("/deleteCashInventorys")
    public void deleteCashInventorys(String cashInventorysId){
        System.out.println("删除 删除");
        cashInventorysService.deleteCashInventorys(cashInventorysId);
    }


}
